package diploma.main;
import java.io.File;
import java.io.FileNotFoundException;

import diploma.main.SolveCandidat2;
import diploma.matrika.MatrikaParov;
import diploma.matrika.MatrikaParov.eTipRazdalje;
import diploma.substitucija.Buffer;
import diploma.tokenizer.Tokenizer;



public class PrimerRazbijanja {

	
	public static void main(String[] args) throws FileNotFoundException
	{
		File sifrirana = new File(args[0]);
		File slovar = new File(args[1]);
		Integer MaxN = Integer.parseInt(args[2]);
		System.out.println("Šifrirana datoteka:" + sifrirana.getAbsolutePath());
		System.out.println("Slovar:            "+ slovar.getAbsolutePath());
		System.out.println("MaxN="+MaxN);
		
		StringBuffer sif = Buffer.file2Buffer(sifrirana);
		StringBuffer slo = Buffer.file2Buffer(slovar);
		
		MatrikaParov matSlovar = new MatrikaParov();
		MatrikaParov matSifrir2 = new MatrikaParov();
		MatrikaParov matSifrir = new MatrikaParov();
		
		matSlovar.posodobiFrekvence(Tokenizer.bufferToList(slo));
		matSifrir2.posodobiFrekvence(Tokenizer.bufferToList(sif, false));
		matSifrir.posodobiFrekvence(Tokenizer.bufferToList(sif, false));
		System.gc();
		
		SolveCandidat2 solve = new SolveCandidat2(matSlovar, matSifrir, eTipRazdalje.manhattan, MaxN);
		solve.doSolve();
		
		System.out.println("Originalno besedilo:");
		System.out.println(sif.toString());
		System.out.println("\n\n");
		System.out.println("Najdena substitucija:");
		solve.getSubstitucijoResitve().izpisiInverznoSubstitucijo();
		System.out.println("Rešeno besedilo:");
		System.out.println(solve.getSubstitucijoResitve().substitucija(sif));
	}
	
	
}

